package q257_binaryTreePaths;

import CommonClass.Common.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    List<String> res = new ArrayList<String>();
    public List<String> binaryTreePaths(TreeNode root) {
        if (root.left == null && root.right == null){
            res.add(Integer.toString(root.val));
            return res;
        }
        String baseStr = Integer.toString(root.val);
        dfs(root, baseStr);
        return res;
    }

    private void dfs(TreeNode root, String baseStr) {
        if (root.left == null && root.right == null){
            res.add(baseStr);
            return;
        }

        if (root.left != null) {
            baseStr = baseStr + "->" + root.left.val;
            dfs(root.left, baseStr);
        }
        if (root.right != null) {
            baseStr = baseStr + "->" + root.right.val;
            dfs(root.right, baseStr);
        }

    }
}
